package shapes;

import processing.core.PApplet;
import util.Color;

public class PolyArc implements Shape{
	public static int sRes = 18;
	private float x, y;
	private float inner, outer;
	private float start, stop;
	private float res;
	private float angleStep;
	private Color color;
	
	public PolyArc(float x, float y, float inner, float outer, float start, float stop, Color color){
		this(x, y, inner, outer, start, stop, color, sRes);
	}
	
	public PolyArc(float x, float y, float inner, float outer, float start, float stop, Color color, int res) {
		this.x = x;
		this.y = y;
		this.inner = inner;
		this.outer = outer;
		this.start = start;
		this.stop = stop;
		this.color = color;

		setRes(res);
	}

	public void draw(PApplet pa) {
		if(color != null) color.fill(pa);
		pa.noStroke();
		float a = start;
		int i = 0;
		pa.beginShape(PApplet.POLYGON);
		while(i <= res){
			pa.vertex(x + outer * pa.cos(start + i*angleStep), y + outer * pa.sin(start + i*angleStep), 0);
			i++;
		}
		
		while(i > 0){
			i--;
			pa.vertex(x + inner * pa.cos(start + i*angleStep), y + inner * pa.sin(start + i*angleStep), 0);
		}
		pa.endShape();	
	}

	public void scale(float s) {
		// TODO Auto-generated method stub
		
	}

	public Color getColor() {
		return color;
	}

	public float getInnerRadius() {
		return inner;
	}

	public float getRes() {
		return res;
	}

	public float getStart() {
		return start;
	}

	public float getStop() {
		return stop;
	}

	public float getOuterRadius() {
		return outer;
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public void setOuterRadius(float outer) {
		this.outer = outer;
	}

	public void setRes(float res) {
		this.res = (int) Math.ceil((stop - start) * res / Math.PI);
		this.angleStep = (stop - start) / this.res;
	}

	public void setStart(float start) {
		this.start = start;
	}

	public void setStop(float stop) {
		this.stop = stop;
	}

	public void setInnerRadius(float inner) {
		this.inner = inner;
	}

	public void setX(float x) {
		this.x = x;
	}

	public void setY(float y) {
		this.y = y;
	}

}
